package com.example.neusoft215gdh.androidpro_21.Adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.neusoft215gdh.androidpro_21.JavaBean.LoveList;
import com.example.neusoft215gdh.androidpro_21.R;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Rainbow on 2017/11/12.
 */

public class LoveAdapter extends RecyclerView.Adapter    {


    private List<LoveList> loveList = new ArrayList<>();
    private Context context;//上下文对象
    private LayoutInflater layoutInflater;

    //构造函数
    public LoveAdapter(Context context, List<LoveList> loveList ){


        this.context=context;//保存上下文
        layoutInflater=LayoutInflater.from(context);
        this.loveList.addAll(loveList);//显示数据

    }




    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View itemView = layoutInflater.inflate(R.layout.item_clublove,parent,false);

        LoveViewHolder holder=new LoveViewHolder(itemView);

        return holder;
    }
    //绑定数据
    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

        LoveViewHolder loveViewHolder = (LoveViewHolder) holder;
        LoveList love  = loveList.get(position);


        //获取具体的数据值
        String name = love.getName();
        String pic = love.getThumb();
        final String ID =love.getFan_id();
        loveViewHolder.love_clubname.setText(name);
        if (pic != "") {
            Picasso.with(context).load("http://172.24.10.175/workout/Uploads/"+pic).
                    into(loveViewHolder.love_pic);
        }


        loveViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {


            }
        });

    }

    //显示条目的数量
    @Override
    public int getItemCount() {
        return loveList.size();
    }


}

